use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use serde_json::{from_str, json, to_string, Value};

#[derive(Debug, Deserialize, Serialize)]
struct Person {
    name: String,
    age: u32,
}

#[test]
fn test1() {
    let p = Person {
        name: "name".to_string(),
        age: 12,
    };

    let json = serde_json::to_string(&p).unwrap();
    println!("json:{}", json);

    let p: Person = serde_json::from_str(&json).unwrap();
    println!("p:{:?}", p);
}

#[test]
fn test2() {
    let json_value = json!({
        "name": "alice",
        "age": 18,
        "sex": 1,
    });

    println!("json_value:{:?}", json_value);

    let person = Person::deserialize(&json_value).unwrap();

    println!("person:{:?}", person);
}
